#include "delay.h"
#include "lpc17xx_clkpwr.h"

#define SYSTEMTICK_CCLK  100000000

volatile uint32_t SysTickCnt = 0;

void SysTick_Handler(void)
{
  SysTickCnt++;
}

void SysTick_Init()
{
  SysTick_Config(SYSTEMTICK_CCLK/ 1000 - 1);
}

void DelayMs(uint32_t n)
{
  volatile uint32_t systick = SysTickCnt;
  volatile uint32_t DValue = 0;
  if(systick > SysTickCnt)
    DValue = (SysTickCnt - systick) ^ 0xffffffff;
  else
    DValue = SysTickCnt - systick;
  while(DValue < n)
  {
    if(systick > SysTickCnt)
      DValue = (SysTickCnt - systick) ^ 0xffffffff;
    else
      DValue = SysTickCnt - systick;
  }
}
